package com.software.seakdream.controller;

import com.software.seakdream.domain.Result;
import com.software.seakdream.entity.*;
import com.software.seakdream.service.AudioInfoService;
import com.software.seakdream.service.DailyAudioService;
import com.software.seakdream.service.UserInfoService;
import com.software.seakdream.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/AudioInfo")
public class AudioInfoController {
    @Autowired
    private AudioInfoService audioInfoService;

    @Autowired
    private DailyAudioService dailyAudioService;
    @GetMapping("/findAudioInfo")
    public List<AudioInfo> getAudioInfo(String type,String category){
        List<AudioInfo> audioInfos = audioInfoService.findAudioInfo(type,category);
        return audioInfos;
    }

    @GetMapping("/findAllAudioInfo")
    public List<AudioInfo> findAllAudioInfo(String type){
        List<AudioInfo> audioInfos = audioInfoService.findAllAudioInfo(type);
        return audioInfos;
    }

    @GetMapping("/findAudioInfoById")
    public Result findAudioInfoById(String audioId) {
        AudioInfo audioInfo = audioInfoService.findAudioInfoById(audioId);
        return ResultUtils.success(audioInfo);
    }

    @GetMapping("/queryFavorite")
    public Result queryFavorite(String userId){
        List<AudioInfo> audioInfos = audioInfoService.queryFavorite(userId);
        if (audioInfos == null){
            return ResultUtils.error("404","错误", null);
        }
        return ResultUtils.success(audioInfos);
    }

    @GetMapping("/queryFavoriteW")
    public Result queryFavoriteW(String userId){
        List<Favorite> audioInfos = audioInfoService.queryFavoriteW(userId);
        if (audioInfos == null){
            return ResultUtils.error("404","错误", null);
        }
        return ResultUtils.success(audioInfos);
    }

    @GetMapping("/getDailyAudio")
    public Result getDailyAudio(String userId, int page) {
        int pageSize = 10;
        List<HistoryRecord> records = dailyAudioService.getDailyAudio(userId, page, pageSize);
        return ResultUtils.success(records);
    }
}
